<?php
class Report extends CI_Controller {

    function __construct() {
        parent::__construct();
        $level_id = $this->session->userdata('logged_in');
        if ($level_id['level_id'] == null) {
            redirect('user/login', 'refresh');
        }
        if ($level_id['level_id'] == 0) {
            redirect('user', 'refresh');
        }
        $this->load->library('fpdf');
        define('FPDF_FONTPATH',$this->config->item('fonts_path'));
		$this->load->model('report_model');
    }

function reports() {
        $output['css_files'] = false;
        $output['title'] = 'Add Service';
        //$output['resv_id'] = $resv_id;
        
        //$this->load->model('reservation_model');
       // $output['data'] = $this->reservation_model->listServ($resv_id);

        $this->load->template('report/report_view',$output);
    }

    function report_service($date1,$date2){
    		$data['a']=$this->report_model->service_report($date1,$date2);
        	$this->load->view('report/pdf_service', $data);

    }
	function report_room($date1,$date2){
		$data['a']=$this->report_model->room_report($date1,$date2);
        $this->load->view('report/pdf_reportroom', $data);
		
	}
	function report_daily($date1,$date2){
		$data['a']=$this->report_model->daily_report($date1,$date2);
        $this->load->view('report/pdf_dailyocc', $data);
		
	}
	function report_dailyocc($date1,$date2){
		$data['a']=$this->report_model->dailyocc_report($date1,$date2);
        $this->load->view('report/pdf_dailyocc', $data);
		
	}
	function report_daily_sales($date1,$date2){
		$data['a']=$this->report_model->daily_sales_report($date1,$date2);
        $this->load->view('report/pdf_daily_sales', $data);
	}
    function report_reservation($date1,$date2){
        $data['a']=$this->report_model->reservation_report($date1,$date2);
        $this->load->view('report/pdf_reservation', $data);
    }
	 function cetak_service($id){
    		$model_service=$this->load->model('model_service');
			$data['a']=$this->model_service->cetak_service($id);
        	$this->load->view('pdf/cetak_service', $data);

    }
	

	function outlet_sales() {
		$data['css_files'] = false;
		$data['title']     = 'Report Outlet Sales';
		
		$this->load->template('report/outlet_sales', $data);
	}


	function daily_outlet_sales($date) {
		$this->load->model('report_model');
		$data['sales'] = $this->report_model->select_daily_service($date)->result_array();
		$data['date'] = $date;
		
		$this->load->view('report/daily_outlet_sales', $data);
	}

	function monthly_outlet_sales($month, $year) {
		$this->load->model('report_model');
		$month = (int) $month;
		$data['sales'] = $this->report_model->select_monthly_service($month, $year)->result_array();
		$data['month'] = $month;
		$data['year'] = $year;
		
		$this->load->view('report/monthly_outlet_sales', $data);
	}
	
	function occupied_room() {
		$data['css_files'] = false;
		$data['title']     = 'Report Occupied Room';
		
		$this->load->template('report/occupied_room', $data);
	}
	
	function daily_occupied_room($date) {
		$this->load->model('report_model');
		$data['rooms'] = $this->report_model->select_daily_occupied($date)->result_array();
		$data['date'] = $date;
		
		$this->load->view('report/daily_occupied_room', $data);
	}
	
	function monthly_occupied_room($month, $year) {
		$this->load->model('report_model');
		$month = (int) $month;
		$data['rooms'] = $this->report_model->select_monthly_occupied($month, $year)->result_array();
		$data['month'] = $month;
		$data['year'] = $year;
		
		$this->load->view('report/monthly_occupied_room', $data);
	}
	
	function vacant_room() {
		$data['css_files'] = false;
		$data['title']     = 'Report Vacant Room';
		
		$this->load->template('report/vacant_room', $data);
	}
	
	function daily_vacant_room($date) {
		$this->load->model('report_model');
		$data['rooms'] = $this->report_model->select_daily_vacant($date)->result_array();
		$data['date'] = $date;
		
		$this->load->view('report/daily_vacant_room', $data);
	}
	
	function monthly_vacant_room($month, $year) {
		$this->load->model('report_model');
		$month = (int) $month;
		$days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
		$rooms = array();
		for($i=0;$i<$days;$i++) {
			$room = $this->report_model->select_daily_vacant($year.'-'.$month.'-'.($i+1))->result_array();
			foreach($room as $row) {
				$row['date'] = $year.'-'.$month.'-'.($i+1);
				$rooms[] = $row;
			}
		}
		$data['rooms'] = $rooms;
		$data['month'] = $month;
		$data['year'] = $year;
		
		$this->load->view('report/monthly_vacant_room', $data);
	}
	
	function reservation_room() {
		$data['css_files'] = false;
		$data['title']     = 'Report Reservation Room';
		
		$this->load->template('report/reservation_room', $data);
	}
	
	function daily_reservation_room($date) {
		$this->load->model('report_model');
		$data['rooms'] = $this->report_model->select_daily_reservation($date)->result_array();
		$data['date'] = $date;
		
		$this->load->view('report/daily_reservation_room', $data);
	}
	
	function monthly_reservation_room($month, $year) {
		$this->load->model('report_model');
		$month = (int) $month;
		$data['rooms'] = $this->report_model->select_monthly_reservation($month, $year)->result_array();
		$data['month'] = $month;
		$data['year'] = $year;
		
		$this->load->view('report/monthly_reservation_room', $data);
	}
	
	function sales() {
		$data['css_files'] = false;
		$data['title']     = 'Report Sales';
		
		$this->load->template('report/sales', $data);
	}
	
	function daily_sales($date) {
		$this->load->model('report_model');
		$res = $this->report_model->select_daily_room($date)->result_array();
		$rooms = array();
		foreach($res as $row) {
			$row['services'] = $this->report_model->select_service_room($row['resv_room_id'])->result_array();
			$row['materials'] = $this->report_model->select_material_room($row['resv_room_id'])->result_array();
			$rooms[] = $row;
		}
		
		$data['rooms'] = $rooms;
		$data['date'] = $date;
		
		$this->load->view('report/daily_sales', $data);
	}
	
	function monthly_sales($month, $year) {
		$this->load->model('report_model');
		$month = (int) $month;
		$res = $this->report_model->select_monthly_room($month, $year)->result_array();
		$rooms = array();
		foreach($res as $row) {
			$row['services'] = $this->report_model->select_service_room($row['resv_room_id'])->result_array();
			$row['materials'] = $this->report_model->select_material_room($row['resv_room_id'])->result_array();
			$rooms[] = $row;
		}
		
		$data['rooms'] = $rooms;
		$data['month'] = $month;
		$data['year'] = $year;
		
		$this->load->view('report/monthly_sales', $data);
	}
	
	function occupancy_ratio() {
		$data['css_files'] = false;
		$data['title']     = 'Report Occupancy Ratio';
		
		$this->load->template('report/occupancy_ratio', $data);
	}
	
	function monthly_occ_report ($month, $year)
	{
	$this->load->model('report_model');
		$month = (int) $month;
		$room = $this->report_model->month_occ_report_get($month,$year)->result_array();
		$data['room'] = $room;
		$data['month'] = $month;
		$data['year'] = $year;

	$this->load->view('report/monthly_occ_report', $data);
	}
	
	function daily_occ_report($date)
	{
	
	$this->load->model('report_model');
		$ratio = array();
		
		$roomlist = $this->report_model->goc()->result_array();
		foreach($roomlist as $row){
		$row2 = $this->report_model->daily_occ_report($date,$row['room_id'])->row_array();
		$row ['ratio'] = $row2['room'];
		$ratio[] = $row;
		
		}
		$data['date'] = $date;
		$data['rooms'] = $ratio;
		$this->load->view('report/daily_occ_report', $data);
	
	}
	
	function information_service($is){
	$this->load->model('report_model');
	
	$data['i'] = $this->report_model->get_information_inv($is)->row_array();
	$data['s'] = $this->report_model->get_service($is)->result_array();
	$data['t'] = $this->report_model->total_service($is)->row_array();
	
	$this->load->view('report/pdf_service', $data);
	
	}

	

}